//
//  HttpUtils.h
//  Weike
//
//  Created by leirz on 14-3-12.
//  Copyright (c) 2014年 winupon. All rights reserved.
//

#import <Foundation/Foundation.h>


/**
 图片质量
 */
typedef enum {
    ImageUploadQualityAuto = 1, // 根据网络状况选择(默认)，WIFI:Middle 2G/3G:Lower
    ImageUploadQualityHigh,
    ImageUploadQualityMiddle,
    ImageUploadQualityLower
} ImageUploadQuality;

@class AFHTTPRequestOperation;

@interface HttpRequest1 : NSObject

/**
 * 获取当前实例
 */
+ (HttpRequest1 *)sharedHttpRequest;

/**
 *  同步POST请求
 *
 *  @param url        请求地址
 *  @param params     请求参数
 *  @param completion 回调函数
 */
- (void)syncPost:(NSString *)url params:(NSDictionary *)params completion:(void (^)(BOOL success, NSString *resultStr))completion;

/**
 *  同步GET请求
 *
 *  @param url        请求地址
 *  @param completion 回调函数
 */
- (void)syncGet:(NSString *)url completion:(void (^)(BOOL success, NSString *resultStr))completion;

/**
 * POST 请求
 * @param url 请求地址
 * @param params 请求参数
 * @param complete 回调函数
 */
- (void)post:(NSString *)url params:(NSDictionary *)params complete:(void (^)(BOOL success, NSDictionary *result))complete;

/**
 * POST 请求
 * @param url 请求地址
 * @param params 请求参数
 * @param complete 回调函数
 * @param errors 是否弹出错误提示
 */
- (void)post:(NSString *)url params:(NSDictionary *)params complete:(void (^)(BOOL success, NSDictionary *result))complete errors:(BOOL)errors;

/**
 * GET请求
 */
- (void)get:(NSString *)url params:(NSDictionary *)params complete:(void (^)(BOOL success, NSDictionary *result))complete;

/**
 * GET请求(无法获取网络连接，是否获取缓存数据)
 */
- (void)get:(NSString *)url params:(NSDictionary *)params useCache:(BOOL)useCache complete:(void (^)(BOOL success, NSDictionary *result))complete;

/**
 * 上传文件
 */
- (AFHTTPRequestOperation *)upload:(NSString *)url
                            params:(NSDictionary *)params
                             files:(NSArray *)files
                          complete:(void (^)(BOOL success, NSDictionary *result))complete;

/**
 * 上传文件
 */
- (AFHTTPRequestOperation *)upload:(NSString *)url
                            params:(NSDictionary *)params
                             files:(NSArray *)files
                           quality:(ImageUploadQuality)quality
                          complete:(void (^)(BOOL success, NSDictionary *result))complete;

/**
 * 上传文件(含上传进度)
 */
- (AFHTTPRequestOperation *)upload:(NSString *)url
                            params:(NSDictionary *)params
                             files:(NSArray *)files
                           process:(void (^)(long long writeBytes, long long totalBytes))process
                          complete:(void (^)(BOOL success, NSDictionary *result))complete;

/**
 * 上传文件(含上传进度)
 */
- (AFHTTPRequestOperation *)upload:(NSString *)url
                            params:(NSDictionary *)params
                             files:(NSArray *)files
                           quality:(ImageUploadQuality)quality
                           process:(void (^)(long long writeBytes, long long totalBytes))process
                          complete:(void (^)(BOOL success, NSDictionary *result))complete;

/**
 * 下载文件
 */
- (AFHTTPRequestOperation *)download:(NSString *)url
                              params:(NSDictionary *)params
                            filePath:(NSString *)filePath
                            complete:(void (^)(BOOL success, NSDictionary *result))complete;

/**
 * 下载文件(含下载进度)
 */
- (AFHTTPRequestOperation *)download:(NSString *)url
                              params:(NSDictionary *)params
                            filePath:(NSString *)filePath
                             process:(void (^)(long long writeBytes, long long totalBytes))process
                            complete:(void (^)(BOOL success, NSDictionary *result))complete;

/**
 *  下周文件
 *
 *  @param url
 *  @param params
 *  @param filePath
 *  @param userInfo
 *  @param process
 *  @param complete
 *
 *  @return <#return value description#>
 */
- (AFHTTPRequestOperation *)download:(NSString *)url
                              params:(NSDictionary *)params
                            filePath:(NSString *)filePath
                            userInfo:(NSDictionary *)userInfo
                             process:(void (^)(long long writeBytes, long long totalBytes))process
                            complete:(void (^)(BOOL success, NSDictionary *result, NSDictionary *userInfo))complete;

@end
